package com.guoxin.part1.chapter6;

import java.util.concurrent.TimeUnit;

/**
 * 线程组优先级
 *
 * @author guoxin
 * @date 2019/8/28
 */
public class ThreadGroupPriority {
    public static void main(String[] args) {
        ThreadGroup group = new ThreadGroup("group1");
        Thread thread = new Thread(group, () -> {
            while (true) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "thread");
        thread.setDaemon(true);
        thread.start();

        System.out.println("group.getMaxPriority=" + group.getMaxPriority());
        System.out.println("thread.getPriority=" + thread.getPriority());
        group.setMaxPriority(3);
        System.out.println("group.getMaxPriority=" + group.getMaxPriority());
        System.out.println("thread.getPriority=" + thread.getPriority());

        Thread thread2 = new Thread(group, () -> {
            while (true) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "thread2");
        System.out.println("thread2.getPriority=" + thread2.getPriority());
    }
}
